//
//  Status.swift
//  weibo19
//
//  Created by Arvin on 15/11/14.
//  Copyright © 2015年 Arvin. All rights reserved.
//

import UIKit

class Status: NSObject {
    // 微博创建时间
    var created_at: String?
    // 微博内容
    var text: String?
    // 微博id
    var id: Int = 0
    // 微博来源
    var source: String?
    // 微博作者的用户信息字段
    var user: User?
    // 配图urlstring
    var pic_urls: [[String: String]]?
    var pic_URLs: [NSURL]? {
        // 初始化数组
        var URLsArr = [NSURL]()
        guard let urls = pic_urls else {
            return nil
        }
        for item in urls {
            // 相信服务器返回的数据能转成URL
            let URL = NSURL(string: item["thumbnail_pic"]!)
            URLsArr.append(URL!)
        }
        return URLsArr
    }
    
    // retweeted 
    var retweeted_status: Status?
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            guard let u = value as? [String: AnyObject] else {
                return // 注意: 一定要加return
            }
            user = User(dict: u)
            return  // 注意: 一定要加return
        }
        
        if key == "retweeted_status" {
            guard let ret = value as? [String: AnyObject] else {
                return
            }
            retweeted_status = Status(dict: ret)
            return
        }
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) { }
    
    
}
